package com.example.projectmanagement.repository.study;

import com.example.projectmanagement.model.study.VideoAccessControl;
import com.example.projectmanagement.model.study.Lesson;
import com.example.projectmanagement.model.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface VideoAccessControlRepository extends JpaRepository<VideoAccessControl, Long> {
    List<VideoAccessControl> findByVideo(Lesson video);
    List<VideoAccessControl> findByStudent(User student);
    List<VideoAccessControl> findByLecturer(User lecturer);
    Optional<VideoAccessControl> findByVideoAndStudent(Lesson video, User student);
    List<VideoAccessControl> findByVideoAndCanView(Lesson video, Boolean canView);
    
    @Query("SELECT vac FROM VideoAccessControl vac WHERE vac.video.id = :videoId AND vac.student.id = :studentId")
    Optional<VideoAccessControl> findByVideoIdAndStudentId(@Param("videoId") Long videoId, @Param("studentId") Long studentId);
}